package com.blrs.controller;

import java.util.List;
import javax.servlet.http.HttpServletResponse;

import com.blrs.common.utils.SecurityUtils;
import com.blrs.service.activity.IActivityRegistrationService;
import com.blrs.system.service.ISysDeptService;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.blrs.common.annotation.Log;
import com.blrs.common.core.controller.BaseController;
import com.blrs.common.core.domain.AjaxResult;
import com.blrs.common.enums.BusinessType;
import com.blrs.domain.ActivityRegistration;
import com.blrs.common.utils.poi.ExcelUtil;
import com.blrs.common.core.page.TableDataInfo;

/**
 * 活动培训报名信息Controller
 * 
 * @author yang
 * @date 2023-12-19
 */
@RestController
@RequestMapping("/activity/registration")
public class ActivityRegistrationController extends BaseController
{
    @Autowired
    private IActivityRegistrationService activityRegistrationService;
    @Autowired
    private ISysDeptService sysDeptService;

    /**
     * 查询活动培训报名信息列表
     */
    @GetMapping("/list")
    public TableDataInfo list(ActivityRegistration activityRegistration)
    {
        startPage();
        activityRegistration.setDeptId(SecurityUtils.getOrgId());
        List<ActivityRegistration> list = activityRegistrationService.selectActivityRegistrationList(activityRegistration);
        return getDataTable(list);
    }

    /**
     * 导出活动培训报名信息列表
     */
    @Log(title = "活动培训报名信息", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, ActivityRegistration activityRegistration)
    {
        activityRegistration.setDeptId(SecurityUtils.getOrgId());
        List<ActivityRegistration> list = activityRegistrationService.selectActivityRegistrationList(activityRegistration);
        ExcelUtil<ActivityRegistration> util = new ExcelUtil<ActivityRegistration>(ActivityRegistration.class);
        util.exportExcel(response, list, "活动培训报名信息数据");
    }

    /**
     * 获取活动培训报名信息详细信息
     */
    @GetMapping(value = "/{applicationId}")
    public AjaxResult getInfo(@PathVariable("applicationId") String applicationId)
    {
        return success(activityRegistrationService.selectActivityRegistrationByApplicationId(applicationId));
    }

    /**
     * 新增活动培训报名信息
     */
    @Log(title = "活动培训报名信息", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody ActivityRegistration activityRegistration)
    {
        return toAjax(activityRegistrationService.insertActivityRegistration(activityRegistration));
    }

    /**
     * 修改活动培训报名信息
     */
    @Log(title = "活动培训报名信息", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody ActivityRegistration activityRegistration)
    {
        return toAjax(activityRegistrationService.updateActivityRegistration(activityRegistration));
    }

    /**
     * 删除活动培训报名信息
     */
    @Log(title = "活动培训报名信息", businessType = BusinessType.DELETE)
	@DeleteMapping("/{applicationIds}/{activityId}")
    public AjaxResult remove(@PathVariable String[] applicationIds,@PathVariable String activityId)
    {
        return toAjax(activityRegistrationService.deleteActivityRegistrationByApplicationIds(applicationIds,activityId));
    }
}
